<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../global/layui/css/layui.css" type="text/css">
    <link rel="stylesheet" href="../../global/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" href="../../global/css/ztree/demo.css" type="text/css">
    
</head>
<style>
#container{
    height: 385px;
}
</style>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form"  enctype="multipart/form-data">
        <fieldset>
            <input type="hidden" id="contextId" name="id">
            <div class="form-group">
                <label class="col-md-2 control-label">类型名称</label>
                <div class="col-md-10" style="margin-top:7px">
                    <select id="type" name="type">
                        <option value="">请选择</option>
                        <option value="2">新人手册</option>
                        <option value="1">公司简介</option>
                    </select>
                </div>
            </div>

            <div class="form-group" >
                <label class="col-md-2 control-label">内容</label>
                <!-- 加载编辑器的容器 -->
                <div class="col-md-10">
                    <textarea id="content" name="content" ></textarea>
                </div>
            </div>
            <div class="form-group" >
                <label class="col-md-2 control-label">状态</label>
                <div class="col-md-10">
                	<select id="status" name="status">
                		<option value="">请选择</option>
                		<option value="1">启用</option>
                		<option value="2">禁用</option>
                	</select>
                </div>
            </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='managetype.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="add()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>

<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/layui/layui.all.js"></script>

<script type="text/javascript" src="../../global/js/libs/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="../../global/js/my/ztree-menu.js"></script>
<script type="text/javascript">
    //富文本编辑


</script>
<script type="text/javascript">
	var layedit;
	var index
    layui.use(['layer', 'layedit'], function () {
        var layer = layui.layer;
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '../../clyjContext/uploadFile' ,//接口url
                type: 'post' //默认post
            }
        });
       
    	index = layedit.build('content'); //建立编辑器
    });
    initData();

     function initData() {
        var contextId = getUrlParam("contextId");
        if (contextId != "") {
            $.ajax({
                type: 'get',
                url: '/clyjContext/' + contextId,
                async: false,
                success: function (data2) {
                    console.info(data2);
                    var data = data2[0];
                    $("#contextId").val(data.id);
                    $("#type").val(data.type);
                    layedit.setContent(index,data.content,false);
                    $("#status").val(data.status);
                }
            });
        }
    } 
    $('#form').bootstrapValidator();

    function add() {

        var bootstrapValidator = $("#form").data('bootstrapValidator');
        var ids = bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        // var ids = getCheckedMenuIds2()
        layedit.sync(index);
         $("form").ajaxSubmit({ 
			type: 'post',
            url: '/clyjContext/saveClass',
            traditional: true,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                   layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                       location.href = "managetype.html";
                   });
               },error:function () {
                console.log("我保存失败了");
            }
		});

       /*  var formdata = $("#form").serializeObject();
        formdata.permissionIds = getCheckedMenuIds2();

        $.ajax({
            type: 'post',
            url: '/clyjGoodsBrand/saveClass',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("成功", {shift: -1, time: 1000}, function () {
                    location.href = "managetype.html";
                });
            }
        }); */
    }

</script>
</body>
</html>
